/**
 * [DragonApp.view.notice.Txt description]
 * 文字公告窗体
 */
Ext.define('DragonApp.view.notice.Txt', {
    extend: 'Ext.window.Window',
    alias: 'widget.notice_txt_window',
    requires: [
        'DragonApp.view.pub.combobox.Tag'
    ],

    layout: 'center',

    bind: {
        title: '{title}'
    },

    closable: true,
    modal: true,

    items: [{
        xtype: 'form',
        padding: 10,
        modelValidation: true,

        layout: {
            type: 'fit',
            align: 'stretch'
        },
        items: [{
            xtype: 'fieldset',
            width: 860,
            title: '公告信息',
            layout: 'anchor',
            padding: '15 20 15 20',
            defaults: {
                afterLabelTextTpl: DragonApp.util.String.required,
                anchor: '100%',
                xtype: 'textfield',
                msgTarget: 'side',
                labelWidth: 75
            },
            items: [{
                    xtype: 'hiddenfield',
                    fieldLabel: '公告ID',
                    name: 'id'
                },
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
                    defaults: {
                        afterLabelTextTpl: DragonApp.util.String.required,
                        anchor: '100%',
                        xtype: 'textfield',
                        msgTarget: 'side',
                        labelWidth: 75
                    },
                    items: [{
                            xtype: 'datetimefield',
                            fieldLabel: '开始时间',
                            margin: '0 12 0 0',
                            allowBlank: false,
                            name: 'begintime',
                            labelWidth: 75
                        },
                        {
                            xtype: 'datetimefield',
                            fieldLabel: '结束时间',
                            margin: '0 12 0 0',
                            allowBlank: false,
                            labelWidth: 75,
                            name: 'endtime'
                        },
                        {
                            xtype: 'multichannelcombo',
                            fieldLabel: '适用渠道',
                            allowBlank: false,
                            labelWidth: 75,
                            name: 'channel'
                        }
                    ]
                },
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
                    defaults: {
                        afterLabelTextTpl: DragonApp.util.String.required,
                        anchor: '100%',
                        xtype: 'textfield',
                        msgTarget: 'side',
                        labelWidth: 75
                    },
                    items: [{
                            xtype: 'tagcombobox',
                            width: 270,
                            labelWidth: 75,
                            editable: false,
                            allowBlank: true,
                            fieldLabel: '选择标签',
                            forceSelection: true,
                            name: 'tag',
                            emptyText: '请选择'
                        }

                    ]
                },
                {
                    xtype: 'textfield',
                    fieldLabel: '公告标题',
                    allowBlank: false,
                    name: 'title',
                    maxLength: 10,
                    maxLengthText: '最大字符数为 {0} 个字符'
                },
                {
                    xtype: 'textarea',
                    height: 200,
                    name: 'content',
                    allowBlank: false,
                    fieldLabel: '公告内容',
                    emptyText: '请输入...',
                    maxLength: 500,
                    maxLengthText: '最大字符数为 {0} 个字符'
                },
                {
                    xtype: 'hiddenfield',
                    fieldLabel: '公告类型',
                    name: 'type',
                    value: 0
                },
                {
                    xtype: 'hiddenfield',
                    fieldLabel: '表单类型',
                    name: 'formtype',
                    itemId: 'formtype'
                }
            ]
        }]
    }],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'bottom',
        ui: 'footer',
        layout: {
            pack: 'end',
            type: 'hbox'
        },
        items: [{
                xtype: 'button',
                text: '重置',
                itemId: 'txtResetBtn',
                iconCls: 'x-fa fa-undo',
                handler: function(button) {
                    button.up('window').down('form').getForm().reset();
                }
            },
            {
                text: '预览',
                itemId: 'previewBtn',
                iconCls: 'x-fa fa-eye',
                handler: function() {

                    var demoCode = '你知道<font>{text="窗", color="255,0,0", font_size=20}</font>';
                    demoCode += '<font>{text="窗", color="255,255,0", font_size=20}</font>';
                    demoCode += '之前明<br>月光吗？';

                    demoCode = Ext.String.htmlEncode(demoCode);

                    var textArea = Ext.ComponentQuery.query('textarea', this.up('window').down('form'))[0];
                    var parser = new CODE();

                    var textAreaContent = parser.CodePrase(textArea.getValue());

                    var win = Ext.create('Ext.window.Window', {
                        title: '预览',
                        modal: true,
                        width: 800,
                        height: 400,
                        resizable: false,
                        closeAction: 'destroy',
                        items: [{
                            xtype: 'tabpanel',
                            defaults: {
                                bodyPadding: 10,
                                scrollable: true
                            },
                            items: [{
                                tabConfig: {
                                    title: '文字预览',
                                    tooltip: '文字预览'
                                },
                                html: textAreaContent
                            }, {
                                tabConfig: {
                                    title: '格式示范',
                                    tooltip: '格式示范'
                                },
                                html: demoCode
                            }]
                        }]/*,
                        buttons: [{
                            text: '取消',
                            iconCls: 'x-fa fa-undo',
                            handler: function(button) {
                                button.up('window').down('tabpanel').destroy();
                                button.up('window').destroy();
                            }
                        }, {
                            text: '确定',
                            iconCls: 'x-fa fa-check',
                            handler: function(button) {
                                button.up('window').down('tabpanel').destroy();
                                button.up('window').destroy();
                            }
                        }]*/
                    }).show();
                }
            },
            {
                xtype: 'button',
                text: '发布',
                iconCls: 'x-fa fa-check',
                listeners: {
                    click: 'onSave'
                }
            }
        ]
    }]
});